<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <form action="save" v-on:submit.prevent="onSubmit">
            <input name="name" type="text" v-model="user.name"></input>
            <button type="submit">submit</button>
        </form>

    </div>


    <script src="vue.min.js"></script>
    <script>
        new Vue({
            el: '#app',
            data: {
                // 定义对象
                user:{

                }
            },
            // 定义方法,可多个
            methods:{
                onSubmit(){
                    if(this.user.name == null){
                        alert("请输入用户名")
                    }else{
                        console.log(this.user.name)
                    }
                }
            }
        })
    </script>
</body>

</html>